import logging

import pytest

from resource.pom.memorandum import Memorandum


class Test:
    app = Memorandum

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1：进入桌面，点击备忘录应用')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        logging.info('预期结果1：备忘录打开无卡死、黑屏、白屏等现象')
        device.assert_current_window(self.app.window_name)
        device.refresh_layout()
        device.assert_text_exist('全部笔记')

        logging.info('步骤2：点击收缩文件夹查看界面布局')
        device.click(*self.app.open_menu)
        logging.info('预期结果2：界面从上至下依次显示为：收缩键、笔记、新建按钮、全部笔记、未分类、已分类(个人、生活、工作...及新建的文件夹名称)、我的收藏、最近删除')
        device.refresh_layout()
        note_x, note_y = device.center_of_element(device.get_element_by_text('笔记'))
        newly_x, newly_y = device.center_of_element(device.get_element_by_text('新建'))
        all_x, all_y = device.center_of_element(device.get_element_by_text('全部笔记', index=1))
        unclassified_x, unclassified_y = device.center_of_element(device.get_element_by_text('未分类'))
        personal_x, personal_y = device.center_of_element(device.get_element_by_text('个人'))
        favor_x, favor_y = device.center_of_element(device.get_element_by_text('我的收藏'))
        recent_del_x, recent_del_y = device.center_of_element(device.get_element_by_text('最近删除'))
        assert note_y > self.app.close_menu[1], '[笔记]不在[收缩键]下面'
        assert newly_x > note_x, '[新建]不在[笔记]右面'
        assert all_y > newly_y, '[全部笔记]不在[新建]下面'
        assert unclassified_y > all_y, '[未分类]不在[全部笔记]下面'
        assert personal_y > unclassified_y, '[个人]不在[未分类]下面'
        assert favor_y > personal_y, '[我的收藏]不在[个人]下面'
        assert recent_del_y > favor_y, '[最近删除]不在[我的收藏]下面'
